package com.example.xcService.pojo.rabbitmq;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.entity.OrderPolling;
import com.example.pojo.enums.PollingEnum;
import com.example.service.IOrderPollingService;
import com.example.xcService.pojo.tool.OrderTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = {"query.fanout.queue"} ,containerFactory = "listenerContainerFactory" ,concurrency = "50-100")
@Slf4j
public class QueryFanoutConsumer {
    @Autowired
    OrderTool orderTool;
    @Autowired
    IOrderPollingService pollingService;

    @RabbitHandler
    @Async
    public  void QueryOrder(String pollingId) throws Exception{
        try{
            Thread.sleep(400);
            LambdaQueryWrapper<OrderPolling> query=new LambdaQueryWrapper<OrderPolling>();
            query.eq(OrderPolling::getPollingId,pollingId);
            query.and(wrappers->wrappers.eq(OrderPolling::getOrderStatus, PollingEnum.UNDERWAY).or().eq(OrderPolling::getOrderStatus,PollingEnum.WRONG).or().eq(OrderPolling::getOrderStatus,PollingEnum.ERROR));
            OrderPolling orderPolling=pollingService.getOne(query);
            if (orderPolling!=null){
                orderTool.Query(orderPolling);
            }
        }catch (Exception ex){
            log.error("查询订单消息队列出错",ex);
        }
    }
}
